package com.nuaa.qianru.run;

        import java.io.File;
        import java.io.FileInputStream;
        import java.io.IOException;
        import java.nio.file.Files;
        import java.text.SimpleDateFormat;
        import java.time.LocalDate;
        import java.time.format.DateTimeFormatter;
        import java.util.Date;
public class CleanFile extends Thread {
    @Override
    public void run() {
        boolean flag = true;
        LocalDate localDate = LocalDate.now();
        String date = localDate.format(DateTimeFormatter.ofPattern("MMdd"));
        System.out.println(date);
        File file = new File("D:\\CG\\img\\res");
        File[] list = file.listFiles();
        int i = 0;
        while(flag && i < list.length - 50 ) {
            File temp = list[i];
            if (temp.getName().substring(0, 4).equals(date)) {

                flag = false;
            } else {
                try {
                    Files.delete(temp.toPath());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            i++;
        }

    }
}
